package com.lewis.system.controller;

import com.lewis.core.base.controller.BaseController;
import com.lewis.core.base.domain.BaseResult;
import com.lewis.core.base.domain.model.RegisterBody;
import com.lewis.core.utils.StringUtil;
import com.lewis.system.service.ISysConfigService;
import com.lewis.system.web.service.SysRegisterService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 注册验证
 *
 * @author Lewis
 */
@Api(tags = "注册验证")
@RestController
public class SysRegisterController extends BaseController {

	@Resource
	private SysRegisterService sysRegisterService;

	@Resource
	private ISysConfigService sysConfigService;

	@ApiOperation(value = "用户注册", notes = "用户注册")
	@PostMapping("/register")
	public BaseResult register(@RequestBody RegisterBody user) {
		if (!("true".equals(sysConfigService.selectConfigByKey("sys.account.registerUser")))) {
			return fail("当前系统没有开启注册功能！");
		}
		String msg = sysRegisterService.register(user);
		return StringUtil.isEmpty(msg) ? ok() : fail(msg);
	}
}